home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / PNL Libraries / MyTrackIdle.p < prev    next >
Text File  |  1996-06-01  |  1KB  |  72 lines

  1. unit MyTrackIdle;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Types;
  7.         
  8.     function IdleSince: longint;  {TickCount at last no idle time}
  9.     procedure StartupTrackIdle;
  10.  
  11. implementation
  12.  
  13.     uses
  14.         Events,
  15.         MyStartup;
  16.         
  17.     type
  18.         keyLongMap = array[1..4] of longint;
  19.  
  20.     var
  21.         lastmoved: longint;  { Last time the cursor was moved, used for idle timing }
  22.         lastpos: Point;
  23.         lastkeymap: keyLongMap;
  24.  
  25.     function IdleSince: longint;  {TickCount at last no idle time}
  26.     begin
  27.         IdleSince := lastmoved;
  28.     end;
  29.  
  30.     procedure MyGetMouse (var pt: Point); { Handles not having quickdraw around }
  31.         var
  32.             event:EventRecord;
  33.             dummy:boolean;
  34.     begin
  35.         dummy:=OSEventAvail(0,event);
  36.         pt := event.where;
  37.     end;
  38.  
  39.     procedure TrackIdle;
  40.         var
  41.             pt: Point;
  42.             km: keyLongMap;
  43.     begin
  44.         pt := lastpos;
  45.         MyGetMouse(lastpos);
  46.         if (abs(pt.h - lastpos.h) > 2) or (abs(pt.v - lastpos.v) > 2) then begin
  47.             lastmoved := TickCount;
  48.         end
  49.         else begin
  50.             GetKeys(keyMap(km));
  51.             if (km[1] <> lastkeymap[1]) or (km[2] <> lastkeymap[2]) or (km[3] <> lastkeymap[3]) or (km[4] <> lastkeymap[4]) then begin
  52.                 lastmoved := TickCount;
  53.                 lastkeymap := km;
  54.             end;
  55.         end;
  56.     end;
  57.  
  58.     function InitTrackIdle( var msg: integer ): OSStatus;
  59.     begin
  60. {$unused(msg)}
  61.         MyGetMouse(lastpos);
  62.         lastmoved := TickCount;
  63.         GetKeys(keyMap(lastkeymap));
  64.         InitTrackIdle := noErr;
  65.     end;
  66.  
  67.     procedure StartupTrackIdle;
  68.     begin
  69.         SetStartup( InitTrackIdle, TrackIdle, 0, nil );
  70.     end;
  71.  
  72. end.